package com.zhouyu.exampleSpSource.service;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author zhouyu
 * @date 2021/8/19 17:34
 * @Description:
 */
@Service
public class Commonservice implements ApplicationContextAware {
    private Map<String, UserService> collectBusinessServiceMap;
    private Map<String, RoleService> roleServiceMap;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        collectBusinessServiceMap = applicationContext.getBeansOfType(UserService.class);
        roleServiceMap = applicationContext.getBeansOfType(RoleService.class);
    }

    public void doUserService() {
        System.out.println("user接口的实现类:"+collectBusinessServiceMap.size());
        for (UserService userService : collectBusinessServiceMap.values()) {
            userService.findUser();
        }

        System.out.println("role接口实现类:"+roleServiceMap.size());
        for (RoleService roleService : roleServiceMap.values()) {
            roleService.getMyRoles();
        }
    }
}
